//
//  InvoiceClaimNewVC.m
//  NtoccShipper
//
//  Created by zcj on 2021/8/11.
//  Copyright © 2021 zhuchongjin. All rights reserved.
//

#import "InvoiceClaimNewVC.h"
#import "InvoiceClaimListModel.h"
#import "InvoiceClaimListCell.h"
#import "ApplyOpenInvoicListVC.h"
#import "ScreenInvoiceClaimView.h"
#import "InvoiceClaimNewVCController.h"
@interface InvoiceClaimNewVC ()<UITableViewDelegate,UITableViewDataSource>{
    FlexFrameView *header;
    FlexFrameView *bottomView;
}

@property (nonatomic,strong) CJTableView *tableView;
@property (nonatomic,strong) NSMutableArray *modelArray;
@property (nonatomic,strong) NSString *refreshType; //刷新
@property (nonatomic,readwrite) int page;
@property (nonatomic,strong) CJLabel *labSumMoney;
@property (nonatomic,strong) CJLabel *labInvioceMoney;
@property (nonatomic,copy) NSString *strCodes;
@property (nonatomic, assign)float allMoney;

//当前页面
@property (nonatomic,copy) NSString *strCurrentSelect;
@property (nonatomic,strong) UIImageView *imgCurrentSelect;

@property (nonatomic,assign) BOOL isSelectAll;
@property (nonatomic,strong) UIImageView *imgAllSelect;
@property (nonatomic,strong) CJLabel *labSelectOrderNums;
@property (nonatomic,copy) NSString *strInvoiceIsAll; // 0 全选  1 不行
@property (nonatomic,copy) NSString *strInvoiceMaxRecord; // 最大条数

@property (nonatomic, strong) CJButton *screenButton;
@property (nonatomic, strong)  ScreenInvoiceClaimView *saixuView;
@property (nonatomic, strong) NSMutableDictionary *dataDic;
@property (nonatomic, strong) NSMutableArray *searchArr;
@property (nonatomic, strong) NSMutableArray *selectedArr;
@property (nonatomic, assign) BOOL isSearch;
@property (nonatomic, strong) FlexTouchView *SelelctAllActionView;
@end

@implementation InvoiceClaimNewVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setTitleName:CJLString(@"发票索取")];
    [self setBackLeftButton:@""];
    
    [self setRightImage:CJLString(@"筛选") image:@""];
    [self createTopView];
    [self.view addSubview:self.tableView];
    
    WS(ws);
    self.tableView.placeHolderView = [[KKTableViewNoDataView alloc] initWithFrame:self.tableView.bounds image:[UIImage imageNamed:@"no_data"] viewClick:^{
        [ws.tableView.mj_header beginRefreshing];
    }];
    [self initData];
    self.dataDic = [NSMutableDictionary dictionary];
    [self loadDataClickAll:NO];
}

/// 创建tableview 等
- (void)createTopView{
    
    CGRect rcFrame = CGRectMake(0, kTopHeight, [[UIScreen mainScreen] bounds].size.width, 0);
    header = [[FlexFrameView alloc] initWithFlex:@"InvoiceClaimListTopView" Frame:rcFrame Owner:self];
    header.flexibleHeight = YES;
    [header layoutIfNeeded];
    
    self.labSumMoney.text = @"运费金额:0.00元";
    self.labInvioceMoney.text = @"发票金额:0.00元";
    [self.view addSubview:header];
    
    
    CGRect rcFrame1 = CGRectMake(0, kScreenHeight - 100, [[UIScreen mainScreen] bounds].size.width, 0);
    bottomView = [[FlexFrameView alloc] initWithFlex:@"InvoiceClaimListBottomView" Frame:rcFrame1 Owner:self];
    bottomView.flexibleHeight = YES;
    [bottomView layoutIfNeeded];
    
    [self.view addSubview:bottomView];
    
}


- (void)initData{
    self.modelArray = [[NSMutableArray alloc]init];
    self.searchArr = [[NSMutableArray array] mutableCopy];
    self.selectedArr = [[NSMutableArray array] mutableCopy];
    self.isSearch = NO;
    self.page = 1;
    self.allMoney = 0.00;
    self.isSelectAll = NO;
    self.strCurrentSelect = @"0";
    self.strInvoiceIsAll = @"1"; // 默认不能全选
    self.strInvoiceMaxRecord = @"";
}

/// <#Description#>
- (void)loadDataClickAll:(BOOL)clickAll{

    NSString *strURL = CJStringWithFormat(@"%@/ntocc-basic-api/invoice/translateInvoice",CJBaseUrl);
    NSDictionary *dicPar = @{@"pageNum":CJStringWithFormat(@"%d",self.page),
                             @"pageSize":@"30",
                             @"invoiceAll":clickAll ? @"1":@"0"
    };
    
    WS(ws);
    [[HDNetworking sharedHDNetworking] dataTaskWithHTTPMethod:GetType url:strURL parameters:dicPar status:ArpaDefault success:^(id  _Nonnull responseObject) {
        
        NSArray *list = responseObject[@"records"];
        NSString *total = CJStringWithFormat(@"%@",responseObject[@"total"]);
        
        NSDictionary *dicSum  = responseObject[@"sumObject"];
        ws.strInvoiceIsAll = CJStringWithFormat(@"%@",dicSum[@"invoiceIsAll"]);
        ws.strInvoiceMaxRecord = CJStringWithFormat(@"%@",dicSum[@"invoiceMaxRecord"]);
        
        if ([ws.refreshType isEqualToString:@"down"]) {
            [ws.modelArray removeAllObjects];
            ws.labSelectOrderNums.text = @"0";
            ws.allMoney = 0.00;
        }
        
        if ([ws.refreshType isEqualToString:@"up"] && list.count > 0) {
            [ws setCancleCurrentStatus];
        }
        
        if (clickAll) {
            if (ws.isSelectAll) {
                [ws setCancleAllStatus];
            }else{
                [ws setSelelctAllStatus];
            }
            [self.selectedArr removeAllObjects];
        }else{
            if (ws.isSelectAll) {
                [self.selectedArr removeAllObjects];
            }
            [ws setCancleAllStatus];
        }
        
        [list enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            NSError * error ;
            InvoiceClaimListModel *model = [[InvoiceClaimListModel alloc]initWithDictionary:obj error:&error];
            model.selected = ws.isSelectAll ? YES:NO;
            for (int i = 0; i < self.selectedArr.count; i++) {
                InvoiceClaimListModel *model1 =self.selectedArr[i];
                if([model.code isEqualToString:model1.code]){
                    model.selected = model1.selected;
                }
            }
            [ws.modelArray addObject:model];
        }];
        __block NSInteger nums = 0;
        //        加载所有
        if (ws.isSelectAll) {
            ws.labSelectOrderNums.text = CJStringWithFormat(@"%ld" ,ws.modelArray.count);
            //      获取选中的总费用
            [self.modelArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                InvoiceClaimListModel *model = (InvoiceClaimListModel *)obj;
                [self.selectedArr addObject:model];
                if (model.selected) {
                    ws.allMoney = ws.allMoney + model.shipperDeliveryFee;
                    nums++;
                }
            }];
        
        }else{
            ws.labSelectOrderNums.text = CJStringWithFormat(@"0");
            //      获取选中的总费用
            [self.selectedArr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                InvoiceClaimListModel *model = (InvoiceClaimListModel *)obj;
                if (model.selected) {
                    ws.allMoney = ws.allMoney + model.shipperDeliveryFee;
                    nums++;
                }
            }];
        }
        
        ws.labSelectOrderNums.text = CJStringWithFormat(@"%ld",nums);
        ws.labSumMoney.text = CJStringWithFormat(@"运费金额:%@元",@(ws.allMoney).cj_money_description);
        ws.labInvioceMoney.text = CJStringWithFormat(@"发票金额:%@元",@(ws.allMoney).cj_money_description);
        
        if (nums == self.modelArray.count) {
            [self setSelelctCurrentStatus];
        }else{
            [self setCancleCurrentStatus];
        }
        
        [ws.tableView.mj_header endRefreshing];
        [ws.tableView.mj_footer endRefreshing];
        
        if (ws.modelArray.count == [total intValue]) {
            [ws.tableView.mj_footer endRefreshingWithNoMoreData];
        }
        
        [ws.tableView reloadData];
        
    } failure:^(NSError * _Nonnull error) {
        [ws.tableView.mj_header endRefreshing];
        [ws.tableView.mj_footer endRefreshing];
    }];
    
    
}

- (void)loadDataSlectedData{
    [self.searchArr removeAllObjects];
    NSString *strURL = CJStringWithFormat(@"%@/ntocc-basic-api/invoice/translateInvoice",CJBaseUrl);
    NSDictionary *dicPar = @{
                             @"invoiceAll":@"1",
                             @"driverName":self.dataDic[@"driverName"],
                             @"vehicleLicense":self.dataDic[@"vehicleLicense"],
                             @"teamName":self.dataDic[@"teamName"],
                             @"fillTimeStart":self.dataDic[@"fillTimeStart"],
                             @"fillTimeEnd":self.dataDic[@"fillTimeEnd"],
                             @"signTimeStart":self.dataDic[@"signTimeStart"],
                             @"signTimeEnd":self.dataDic[@"signTimeEnd"],
                             @"gmtModifiedStart":self.dataDic[@"gmtModifiedStart"],
                             @"gmtModifiedEnd":self.dataDic[@"gmtModifiedEnd"],
                             @"orderGmtCreatedStart":self.dataDic[@"orderGmtCreatedStart"],
                             @"orderGmtCreatedEnd":self.dataDic[@"orderGmtCreatedEnd"],
                             @"gmtCreatedStart":self.dataDic[@"gmtCreatedStart"],
                             @"gmtCreatedEnd":self.dataDic[@"gmtCreatedEnd"]
    };
    
    WS(ws);
    [[HDNetworking sharedHDNetworking] dataTaskWithHTTPMethod:GetType url:strURL parameters:dicPar status:ArpaDefault success:^(id  _Nonnull responseObject) {
        
        NSArray *list = responseObject[@"records"];
        NSString *total = CJStringWithFormat(@"%@",responseObject[@"total"]);
        
        NSDictionary *dicSum  = responseObject[@"sumObject"];
        ws.strInvoiceIsAll = CJStringWithFormat(@"%@",dicSum[@"invoiceIsAll"]);
        ws.strInvoiceMaxRecord = CJStringWithFormat(@"%@",dicSum[@"invoiceMaxRecord"]);
        
        if ([ws.refreshType isEqualToString:@"down"]) {
            [ws.searchArr removeAllObjects];
            ws.labSelectOrderNums.text = @"0";
            ws.allMoney = 0.00;
        }
        
        if ([ws.refreshType isEqualToString:@"up"] && list.count > 0) {
            [ws setCancleCurrentStatus];
        }

//        if (clickAll) {
//            if (ws.isSelectAll) {
//                [ws setCancleAllStatus];
//            }else{
//                [ws setSelelctAllStatus];
//            }
//        }else{
//            [ws setCancleAllStatus];
//        }
//
        [list enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            NSError * error ;
            InvoiceClaimListModel *model = [[InvoiceClaimListModel alloc]initWithDictionary:obj error:&error];
            model.selected = ws.isSelectAll ? YES:NO;
            for (int i = 0; i < self.selectedArr.count; i++) {
                InvoiceClaimListModel *model1 =self.selectedArr[i];
                if([model.code isEqualToString:model1.code]){
                    model.selected = model1.selected;
                }
            }
            [ws.searchArr addObject:model];
        }];

        //        加载所有
        if (ws.isSelectAll) {
            ws.labSelectOrderNums.text = CJStringWithFormat(@"%ld" ,ws.modelArray.count);
        }else{
            ws.labSelectOrderNums.text = CJStringWithFormat(@"0");
        }

        //      获取选中的总费用
        self.allMoney = 0.00;
        __block NSInteger nums = 0;
        [self.selectedArr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            InvoiceClaimListModel *model = (InvoiceClaimListModel *)obj;
            if (model.selected) {
                ws.allMoney = ws.allMoney + model.shipperDeliveryFee;
                nums++;
            }
        }];

        ws.labSelectOrderNums.text = CJStringWithFormat(@"%ld",nums);
        ws.labSumMoney.text = CJStringWithFormat(@"运费金额:%@元",@(ws.allMoney).cj_money_description);
        ws.labInvioceMoney.text = CJStringWithFormat(@"发票金额:%@元",@(ws.allMoney).cj_money_description);

        if (nums == self.modelArray.count) {
            [self setSelelctCurrentStatus];
        }else{
            [self setCancleCurrentStatus];
        }
//
        [ws.tableView.mj_header endRefreshing];
        [ws.tableView.mj_footer endRefreshing];
        
        [ws.tableView reloadData];
        
    } failure:^(NSError * _Nonnull error) {
        [ws.tableView.mj_header endRefreshing];
        [ws.tableView.mj_footer endRefreshing];
    }];
    
    
}
- (void)downRefresh{
    self.refreshType = @"down";
    self.page = 1;
    if(self.isSearch){
        [self loadDataSlectedData];
    }else{
        [self loadDataClickAll:NO];
    }
   
}

- (void)upRefresh{
    self.refreshType = @"up";
    self.page ++;
    if(self.isSearch){
        [self.tableView.mj_footer endRefreshing];
    }else{
        [self loadDataClickAll:NO];
    }
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (self.isSearch == YES) {
        return self.searchArr.count;
    }else{
        return self.modelArray.count;
    }
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *identifier = @"InvoiceClaimListCell";
    InvoiceClaimListCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[InvoiceClaimListCell alloc] initWithFlex:@"InvoiceClaimListCell" reuseIdentifier:identifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
    }
    InvoiceClaimListModel *model ;
    if (self.isSearch == YES) {
        model = self.searchArr[indexPath.row];
    }else{
        model = self.modelArray[indexPath.row];
    }
    [cell setCellInfoModel:model];
    
    WS(ws);
    cell.blockSeclect = ^(id anyObject) {
        [ws selectRowAtIndexPath:indexPath];
        
    };
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [self selectRowAtIndexPath:indexPath];
}


#pragma mark ----------数据处理

- (void)selectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    InvoiceClaimListModel *model ;
    if(self.isSearch == YES){
        model = self.searchArr[indexPath.row];
    }else{
        model = self.modelArray[indexPath.row];
    }
    
    if (model.selected) {
        model.selected = NO;
        for (int i = 0; i < self.selectedArr.count; i++) {
            InvoiceClaimListModel *cenModel = self.selectedArr[i];
            if([cenModel.code isEqualToString:model.code]){
                [self.selectedArr removeObjectAtIndex:i];
            }
        }
    }else{
        model.selected = YES;
        [self.selectedArr addObject:model];
    }
    [self.tableView reloadRowAtIndexPath:indexPath withRowAnimation:UITableViewRowAnimationFade];
    self.allMoney = 0.00;
    __block NSInteger nums = 0;
    
    WS(ws);
    [self.selectedArr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        InvoiceClaimListModel *model = (InvoiceClaimListModel *)obj;
        if (model.selected) {
            ws.allMoney = ws.allMoney + model.shipperDeliveryFee;
            nums++;
        }
    }];
    
    self.labSumMoney.text = CJStringWithFormat(@"运费金额:%@元",@(ws.allMoney).cj_money_description);
    self.labInvioceMoney.text = CJStringWithFormat(@"发票金额:%@元",@(ws.allMoney).cj_money_description);
    self.labSelectOrderNums.text = CJStringWithFormat(@"%ld",nums);
    if (nums == self.modelArray.count) {
        [self setSelelctCurrentStatus];
    }else{
        [self setCancleCurrentStatus];
        // 取消全部全选
        self.isSelectAll = NO;
        self.imgAllSelect.image = [UIImage imageNamed:@"zcj_unSelectedCir"];
    }
    //    [self setCancleAllStatus];
}


- (void)setSelelctCurrentStatus{
    self.strCurrentSelect = @"1";
    self.imgCurrentSelect.image = [UIImage imageNamed:@"zcj_selectedCir"];
    //    [self setCancleAllStatus];
}

- (void)setCancleCurrentStatus{
    self.strCurrentSelect = @"0";
    self.imgCurrentSelect.image = [UIImage imageNamed:@"zcj_unSelectedCir"];
    self.isSelectAll = NO;
    self.imgAllSelect.image = [UIImage imageNamed:@"zcj_unSelectedCir"];
    //    [self setCancleAllStatus];
}

- (void)setSelelctAllStatus{
    self.isSelectAll = YES;
    self.imgAllSelect.image = [UIImage imageNamed:@"zcj_selectedCir"];
    [self setSelelctCurrentStatus];
}

- (void)setCancleAllStatus{
    self.isSelectAll = NO;
    self.allMoney = 0.00;
    self.imgAllSelect.image = [UIImage imageNamed:@"zcj_unSelectedCir"];
    [self setCancleCurrentStatus];
}
- (void)orderNumbersAction{
    InvoiceClaimNewVCController *invVC = [[InvoiceClaimNewVCController alloc] init];
    invVC.modelArray = self.selectedArr;
    __block NSInteger nums = 0;
    self.allMoney = 0.00;
    WS(ws);
    invVC.invoBlock = ^(NSMutableArray * _Nonnull arr) {
        [ws.selectedArr removeAllObjects];
        [arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            InvoiceClaimListModel *model = arr[idx];
            [ws.selectedArr addObject:model];
            nums++;
            ws.allMoney = ws.allMoney + model.shipperDeliveryFee;
        }];
        self.labSumMoney.text = CJStringWithFormat(@"运费金额:%@元",@(ws.allMoney).cj_money_description);
        self.labInvioceMoney.text = CJStringWithFormat(@"发票金额:%@元",@(ws.allMoney).cj_money_description);
        self.labSelectOrderNums.text = CJStringWithFormat(@"%ld",nums);
        if (nums == self.modelArray.count) {
            [self setSelelctCurrentStatus];
        }else{
            [self setCancleCurrentStatus];
            // 取消全部全选
            self.isSelectAll = NO;
            self.imgAllSelect.image = [UIImage imageNamed:@"zcj_unSelectedCir"];
        }
        [self.tableView reloadData];
    };
   
    if(self.selectedArr.count > 0){
        [self pushVc:invVC];
    }
}
/// 选择当前页面
- (void)touchSelelctCurrentAction{
    
    if ([self.strCurrentSelect isEqualToString:@"0"]) {
        [self setSelelctCurrentStatus];
    }else{
        [self setCancleCurrentStatus];
    }
    
    WS(ws);
    if(ws.isSearch){
        [self.searchArr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            
            InvoiceClaimListModel *model = ws.searchArr[idx];
            if ([ws.strCurrentSelect isEqualToString:@"0"]) {
                model.selected = NO;
                for (int i = 0; i < ws.selectedArr.count; i++) {
                    InvoiceClaimListModel *model1 = ws.selectedArr[i];
                    if([model.code isEqualToString:model1.code]){
                        [self.selectedArr removeObjectAtIndex:i];
                    }
                }
            }else{
                model.selected = YES;
                BOOL isCunzai = NO;
                for (int i = 0; i < ws.selectedArr.count; i++) {
                    InvoiceClaimListModel *model1 = ws.selectedArr[i];
                    if([model.code isEqualToString:model1.code]){
                        isCunzai = YES;
                        break;
                    }
                }
                if(!isCunzai){
                    [self.selectedArr addObject:model];
                }
            }
            
        }];
    }else{
        [self.modelArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            
            InvoiceClaimListModel *model = ws.modelArray[idx];
            if ([ws.strCurrentSelect isEqualToString:@"0"]) {
                model.selected = NO;
                for (int i = 0; i < ws.selectedArr.count; i++) {
                    InvoiceClaimListModel *model1 = ws.selectedArr[i];
                    if([model.code isEqualToString:model1.code]){
                        [self.selectedArr removeObjectAtIndex:i];
                    }
                }
            }else{
                model.selected = YES;
                BOOL isCunzai = NO;
                for (int i = 0; i < ws.selectedArr.count; i++) {
                    InvoiceClaimListModel *model1 = ws.selectedArr[i];
                    if([model.code isEqualToString:model1.code]){
                        isCunzai = YES;
                    }
                }
                if(!isCunzai){
                    [self.selectedArr addObject:model];
                }
            }
        }];
    }
    [self selectedArrayMoney];
}

//选择的数组遍历求金额
- (void)selectedArrayMoney{
    __block NSInteger nums = 0;
    self.allMoney = 0.00;
    
    WS(ws);
    [self.selectedArr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        InvoiceClaimListModel *model = ws.selectedArr[idx];
        if ([ws.strCurrentSelect isEqualToString:@"0"]) {
            model.selected = NO;
            nums++;
            ws.allMoney = ws.allMoney + model.shipperDeliveryFee;
        }else{
            model.selected = YES;
            nums++;
            ws.allMoney = ws.allMoney + model.shipperDeliveryFee;
        }
    }];
    self.labSumMoney.text = CJStringWithFormat(@"运费金额:%@元",@(ws.allMoney).cj_money_description);
    self.labInvioceMoney.text = CJStringWithFormat(@"发票金额:%@元",@(ws.allMoney).cj_money_description);
    self.labSelectOrderNums.text = CJStringWithFormat(@"%ld",nums);
    [self.tableView reloadData];
}
/// 选择所有数据
- (void)touchSelelctAllAction{
    
    if ([self.strInvoiceIsAll isEqualToString:@"1"]) {
        
        [CJAlert showStringDismissWithDelay:CJStringWithFormat(@"全选最大条数为%@,已超最大条数,无法进行全选",self.strInvoiceMaxRecord)];
        return;
    }
    
    self.refreshType = @"down";
    self.page = 1;
    [self loadDataClickAll:self.isSelectAll ? NO:YES];
}


- (void)btnSaveInfoAction{
    //    [CJAlert showStringDismissWithDelay:CJStringWithFormat(@"self.indexPage======%@",self.indexPage)];
    NSMutableArray *arrCodes = [[NSMutableArray alloc]initWithCapacity:1];
    __block  NSString *strCode = @"";
    [self.selectedArr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        InvoiceClaimListModel *model = (InvoiceClaimListModel *)obj;
        if (model.selected) {
            [arrCodes addObject:model.code];
        }
    }];
    
    if (arrCodes.count > 0) {
        
        [arrCodes enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if (idx == 0) {
                strCode = obj;
            }else{
                strCode = CJStringWithFormat(@"%@,%@",strCode,obj);
            }
        }];
    }
    
    if ([strCode isEqualToString:@""]) {
        [CJAlert showStringDismissWithDelay:@"请选择需要索取的发票"];
    }else{
        
        WS(ws);
        ApplyOpenInvoicListVC *vc = [ApplyOpenInvoicListVC new];
        vc.strCode = strCode;
        vc.strOpenType = @"";
        vc.blockSucess = ^(id anyObject) {
            [ws.tableView.mj_header beginRefreshing];
        };
        [self pushVc:vc];
    }
    
}


#pragma mark ----------lazy

- (CJTableView *)tableView{
    
    if (!_tableView) {
        _tableView = CJTableView.tbInitFrameStyle(CGRectMake(0, CJTableToTopHeight +header.bottom + LW(15), kScreenWidth, kScreenHeight-kTopHeight - 100 -CJTableToTopHeight - header.height - LW(15)),UITableViewStylePlain)
            .tbDelegate(self)
            .tbDataSource(self)
            .tbSetOther(YES)
            .tbEstimatedRowHeight(YES)
            .tbMjHeadFooter(YES)
        ;
        WS(ws);
        _tableView.blockMjHeader = ^(BOOL isheader) {
            
            if (isheader) {
                [ws downRefresh];
            } else {
                [ws upRefresh];
            }
        };
    }
    
    return _tableView;
}


- (ScreenInvoiceClaimView *)saixuView{
    if(!_saixuView){
        self.saixuView = [[ScreenInvoiceClaimView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        WS(ws);
        self.saixuView.blokHidden = ^{
            ws.saixuView.hidden = YES;
        };
        self.saixuView.confirmBlock = ^(NSMutableDictionary *dic) {
            ws.saixuView.hidden = YES;
            [ws.searchArr removeAllObjects];
            ws.dataDic = dic;
            //遍历dic是否为空置
            NSArray *keys = ws.dataDic.allKeys;
            BOOL isValueNull = YES;
            for (int i = 0; i < keys.count; i++) {
                NSString * key = [keys objectAtIndex:i];
                NSString *str = [ws.dataDic valueForKey:key];
                if([str isEqualToString:@""]){
                    isValueNull = NO;
                }
            }
            if(isValueNull == YES){
                ws.isSearch = NO;
                [ws.tableView reloadData];
                ws.SelelctAllActionView.hidden = NO;
            }else{
                ws.isSearch = YES;
               [ws loadDataSlectedData];
                [ws setCancleCurrentStatus];
                ws.SelelctAllActionView.hidden = YES;
            }
        };
        self.saixuView.clearDataBlock = ^(NSMutableDictionary * _Nullable dic) {
            ws.saixuView.hidden = YES;
            ws.SelelctAllActionView.hidden = NO;
            [ws setCancleCurrentStatus];
//            [ws.modelArray removeAllObjects];
//            ws.dataDic = dic;
//            [ws loadDataClickAll:NO];
            ws.isSearch = NO;
            if (ws.selectedArr.count == ws.modelArray.count) {
                [ws setSelelctAllStatus];
            }else{
                [ws setCancleAllStatus];
            }
            [ws.tableView reloadData];
        };
    }
    return _saixuView;
}
- (void)RightTextClick:(UIButton *)sender{
    [[UIApplication sharedApplication].keyWindow addSubview:self.saixuView];
    self.saixuView.hidden = NO;
}
@end
